<template>
  <div class="cancel-advance">
    <div class="submit-btn-wrapper">
      <a-button v-debounce type="primary" @click="batchCancelHandle" :loading="loading">批量取消</a-button>
    </div>
    <div class="table-content">
      <vxe-table ref="tableRef" :data="tableData" :loading="loading" border show-overflow="title" height="100%" :scroll-y="{ enabled: true, gt: 50 }">
        <vxe-column type="checkbox" width="50"> </vxe-column>
        <vxe-column minWidth="140" field="waybillNum" title="运单号"></vxe-column>
        <vxe-column minWidth="70" field="itemNumber" title="件数"></vxe-column>
        <vxe-column minWidth="70" field="countryRegionName" title="国家/地区"></vxe-column>
        <vxe-column minWidth="160" field="channelName" title="渠道"></vxe-column>
        <vxe-column minWidth="120" field="remark" title="备注"></vxe-column>
        <vxe-column minWidth="70" field="action" title="操作">
          <template #default="{ row }">
            <a-button @click="singleCancelHandle(row)" type="link" danger>取消预报</a-button>
          </template>
        </vxe-column>
      </vxe-table>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { toRefs, watch } from "vue";
import InitHook from "./composables/initHook";
import OperationHook from "./composables/operationHook";
const props = withDefaults(
  defineProps<{
    visible: boolean;
    passData: Base.GeneraDataType;
  }>(),
  {}
);
const emit = defineEmits<{
  (e: "update:visible", visible: boolean): void;
  (e: "submit", state: any): void;
}>();
const { visible, passData } = toRefs(props);
const { tableData, loading, tableRef, selectRows } = InitHook();
const { init, batchCancelHandle, singleCancelHandle } = OperationHook({ tableData, loading, emit, tableRef, selectRows, passData });
init(passData.value.id);
watch(
  () => visible.value,
  (v: boolean) => {
    if (v) {
      init(passData.value.id);
    } else {
      tableRef.value.clearCheckboxRow();
    }
  }
);
</script>
<style lang="stylus" scoped>
.cancel-advance{
    background-color: #fff;
    padding-bottom: 12px;
    .table-content{
        padding: 0 12px;
        height: calc(100vh - 160px);
    }
    .submit-btn-wrapper{
       padding: 12px;
    }
}
</style>
